using System.ComponentModel;
using System.Workflow.ComponentModel;
using TechHeadBrothers.Portal.Web.SilverlightStreaming;

namespace TechHeadBrothers.Workflows.Activities
{
    /// <summary>
    /// Activity that generates a video manifest for the Silverlight Hosting
    /// </summary>
    public partial class GenerateManifest : Activity
    {
        public static DependencyProperty ManifestPathProperty =
            DependencyProperty.Register("ManifestPath", typeof (string), typeof (GenerateManifest));

        public static DependencyProperty VideoPathProperty =
            DependencyProperty.Register("VideoPath", typeof (string), typeof (GenerateManifest));

        /// <summary>
        /// Initializes a new instance of the <see cref="GenerateManifest"/> class.
        /// </summary>
        public GenerateManifest()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the video path.
        /// </summary>
        /// <value>The video path.</value>
        [Description("Video path to upload")]
        [Category("Silverlight")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string VideoPath
        {
            get { return ((string) (GetValue(VideoPathProperty))); }
            set
            {
                SetValue(VideoPathProperty, value);
                //this.ManifestPath=
            }
        }

        /// <summary>
        /// Gets or sets the manifest path.
        /// </summary>
        /// <value>The manifest path.</value>
        [Description("Manifest path of the video")]
        [Category("Silverlight")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string ManifestPath
        {
            get { return ((string) (GetValue(ManifestPathProperty))); }
            set { SetValue(ManifestPathProperty, value); }
        }

        /// <summary>
        /// Called by the workflow runtime to execute an activity.
        /// </summary>
        /// <param name="executionContext">The <see cref="T:System.Workflow.ComponentModel.ActivityExecutionContext"></see> to associate with this <see cref="T:System.Workflow.ComponentModel.Activity"></see> and execution.</param>
        /// <returns>
        /// The <see cref="T:System.Workflow.ComponentModel.ActivityExecutionStatus"></see> of the run task, which determines whether the activity remains in the executing state, or transitions to the closed state.
        /// </returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            ManifestPath = SilverlightStreamingManager.SaveManifest(VideoPath);
            return base.Execute(executionContext);
        }
    }
}